package org.mindrive.system.aspect;

import org.mindrive.system.service.system.LogService;

import javax.annotation.Resource;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogOperationAspect {

	@Resource
	private LogService logService;

//	@Pointcut("execution(public * org.mindrive.system.system.web..*(..))")
	@Pointcut("@annotation( org.mindrive.system.annotation.LogOperation)")
	public void optlog() {
	}

	@Around("optlog()")
	public Object arround(ProceedingJoinPoint point) throws Throwable {
		Object res = null;
		long time = System.currentTimeMillis();
		try {
			res = point.proceed();
			time = System.currentTimeMillis() - time;
		} finally {
			// 方法执行完成后增加日志
			logService.saveEvent(point, res, time);
		}
		return res;
	}

}
